define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    // add_url: 'user/user/add',
                    // edit_url: 'user/user/edit',
                    // del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    integral_url:  'user/integral/index?id',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                searchFormVisible: true,
                commonSearch: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'vehicle.mergename', title: __('Cartype'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'price_sum', title: __('Price_sum'), operate: false},
                        {field: 'number', title: __('Number'), operate: false},
                        {field: 'unit_number', title: __('Unit_number'), operate: false},
                        {field: 'score', title: __('Score'), operate: false, sortable: true},
                        {field: 'status', title: __('加入黑名单'),operate: false, searchList: {"hidden": '加入黑名单', "normal": '移除黑名单'},  table: table, formatter: Table.api.formatter.toggle},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'deal',
                                    text: '交易记录',
                                    extend: 'data-area=\'["100%", "100%"]\'',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url:  'order/order/index?uid={id}',
                                    visible: true

                                },
                                {
                                    name: 'integral',
                                    text: '积分记录',
                                    extend: 'data-area=\'["100%", "100%"]\'',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: $.fn.bootstrapTable.defaults.extend.integral_url,
                                    visible: true
                                }
                            ]
                        }
                    ]
                ]
            });

            table.on("load-success.bs.table", function (e, data){
                $("#num").text(data.total);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});